import {createRouter,createWebHashHistory} from 'vue-router'

const routes = [
  {
    path: "/",
    name: "Home",
    redirect: "/frontend/enterprise-home",
    hidden: true,
  },
  // 前台：企业主页、岗位列表
  {
    path: "/frontend",
    name: "Frontend",
    meta: { title: "前台", icon: 'home' },
    component: () => import("@/layout/job/index.vue"),
    children: [
      {
        path: "enterprise-home",
        name: "FrontendEnterpriseHome",
        meta: { title: "企业主页" },
        component: () => import("@/views/frontend/EnterpriseHome.vue"),
      },
      {
        path: "job-list",
        name: "FrontendJobList",
        meta: { title: "岗位列表" },
        component: () => import("@/views/frontend/JobList.vue"),
      },
    ],
  },
  // 后台：岗位管理、企业信息管理、员工管理
  {
    path: "/admin",
    name: "Admin",
    meta: { title: "后台", icon: 'system' },
    component: () => import("@/layout/job/index.vue"),
    children: [
      {
        path: "job-management",
        name: "AdminJobManagement",
        meta: { title: "岗位管理" },
        component: () => import("@/views/admin/JobManagement.vue"),
      },
      {
        path: "enterprise-info",
        name: "AdminEnterpriseInfo",
        meta: { title: "企业信息管理" },
        component: () => import("@/views/admin/EnterpriseInfo.vue"),
      },
      {
        path: "employee-management",
        name: "AdminEmployeeManagement",
        meta: { title: "员工管理" },
        component: () => import("@/views/admin/EmployeeManagement.vue"),
      },
    ],
  },
  // 兼容旧绝对路径：全部重定向到新分组路径，避免丢失 /admin 或 /frontend 前缀
  { path: "/enterprise-home", redirect: "/frontend/enterprise-home", hidden: true },
  { path: "/job-list", redirect: "/frontend/job-list", hidden: true },
  { path: "/job-management", redirect: "/admin/job-management", hidden: true },
  { path: "/enterprise-info", redirect: "/admin/enterprise-info", hidden: true },
  { path: "/employee-management", redirect: "/admin/employee-management", hidden: true },
  {
    path:'/:pathMatch(.*)*',
    redirect:'/frontend/enterprise-home',
    hidden:true
  }
];

const router=createRouter({
    routes,
    history:createWebHashHistory(import.meta.env.BASE_URL)
})

export default router